#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
DIP分组HTTP接口客户端使用示例
"""

import requests
import json

def test_single_patient():
    """测试单个患者分析"""
    url = "http://localhost:5000/dip/analyze"
    
    # 单个患者数据
    patient_data = {
        "patient_data": {
            "诊断编码": "Z45.0",
            "年龄": 65,
            "住院天数": 5,
            "主手术": "556656",
            "其它手术": "",
            "治疗操作": "",
            "诊断操作": ""
        }
    }
    
    try:
        response = requests.post(url, json=patient_data)
        result = response.json()
        
        print("=== 单个患者分析结果 ===")
        print(json.dumps(result, ensure_ascii=False, indent=2))
        
    except Exception as e:
        print(f"请求失败: {e}")

def test_multiple_patients():
    """测试多个患者分析"""
    url = "http://localhost:5000/dip/analyze"
    
    # 多个患者数据
    patients_data = {
        "patient_data": [
            {
                "诊断编码": "Z45.0",
                "年龄": 65,
                "住院天数": 5,
                "主手术": "556656",
                "其它手术": "",
                "治疗操作": "",
                "诊断操作": ""
            },
            {
                "诊断编码": "A17.8",
                "年龄": 45,
                "住院天数": 15,
                "主手术": "",
                "其它手术": "",
                "治疗操作": "",
                "诊断操作": ""
            }
        ]
    }
    
    try:
        response = requests.post(url, json=patients_data)
        result = response.json()
        
        print("=== 多个患者分析结果 ===")
        print(json.dumps(result, ensure_ascii=False, indent=2))
        
    except Exception as e:
        print(f"请求失败: {e}")

def test_health_check():
    """测试健康检查接口"""
    url = "http://localhost:5000/dip/health"
    
    try:
        response = requests.get(url)
        result = response.json()
        
        print("=== 健康检查结果 ===")
        print(json.dumps(result, ensure_ascii=False, indent=2))
        
    except Exception as e:
        print(f"健康检查失败: {e}")

if __name__ == "__main__":
    print("开始测试DIP分组HTTP接口...")
    
    # 1. 健康检查
    test_health_check()
    
    # 2. 单个患者测试
    test_single_patient()
    
    # 3. 多个患者测试
    test_multiple_patients()
    
    print("测试完成！") 